package cn.jingyuan.swan.paging.web.controller;

import cn.jingyuan.bee.fastjson.FastJsonUtils;
import cn.jingyuan.bee.paging.PageBean;
import cn.jingyuan.bee.paging.PageQueryBean;
import cn.jingyuan.swan.paging.model.po.Book;
import cn.jingyuan.swan.paging.web.controller.model.qo.BookQo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@Slf4j
@RestController
public class BookController {

    /*
        请求参数：
            simple 1：
                {
                  "queryModel": {
                    "bookName": "book",
                    "price": 20.00
                  }
                }

            simple 2：
                {
                  "page": 1,
                  "pageSize": 10,
                  "queryModel": {
                    "bookName": "book",
                    "price": 20.00
                  }
                }

     */
    @PostMapping(path = "/v1/book/list", produces = APPLICATION_JSON_VALUE)
    public PageBean<Book> getBooks(@RequestBody PageQueryBean<BookQo> query) {
        log.info("query:\n{}", FastJsonUtils.jsonPretty(query));

        // 根据 PageQueryBean<BookQo> query 参数作具体的业务处理
        List<Book> books = Arrays.asList(new Book());

        return PageBean.build(1, 10, 55, books);
    }

}
